package pl.edu.agh.neuraleconomy.core.nn;

import lombok.Getter;

import org.encog.engine.network.activation.ActivationLinear;
import org.encog.engine.network.activation.ActivationSigmoid;
import org.encog.mathutil.randomize.ConsistentRandomizer;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;

public class SimpleNetwork {
	private final static double RANDOMIZE_CONST = 1;
	@Getter
	int input;
	@Getter
	int output;

	@Getter
	public BasicNetwork network;
	
	public SimpleNetwork(NetworkStructure structure){
		this(structure.getInputLen(), structure.getSecondLayer(), structure.getThirdLayer(), structure.getOutputLen());
	}

	public SimpleNetwork(int input, int hidden1, int hidden2, int output) {
		// network = EncogUtility.simpleFeedForward(input, hidden1, hidden2,
		// output, false);
		// network.reset();
		network = new BasicNetwork();
		network.addLayer(new BasicLayer(null, false, input));
		if (hidden1 > 0) {
			network.addLayer(new BasicLayer(new ActivationSigmoid(), true, hidden1));
		}
		if (hidden2 > 0) {
			network.addLayer(new BasicLayer(new ActivationSigmoid(), true, hidden2));
		}
		network.addLayer(new BasicLayer(new ActivationLinear(), false, output));
		network.getStructure().finalizeStructure();
		network.reset();
		this.input = input;
		this.output = output;
		randomize();
	}

	private void randomize() {
		(new ConsistentRandomizer(-RANDOMIZE_CONST, RANDOMIZE_CONST)).randomize(network);
	}

}
